#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <unistd.h>

int main(void)
{
    printf("Hello tcp\r\n");

    int ret;
    
    int tcp_client = socket(AF_INET, SOCK_STREAM, 0);

    if(tcp_client == -1)
    {
        printf("socket errer\r\n");
    }

    struct sockaddr_in server_addr = {0};
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(6228);
    server_addr.sin_addr.s_addr = inet_addr("192.168.238.1");

    ret = connect(tcp_client, (const struct sockaddr *)&server_addr, sizeof(server_addr));
    if(ret < 0)
    {
        printf("connect errer\r\n");
    }
    else
    {
        printf("connect success\r\n");
    }

    char sendbuf[] = {"hello world\r\n"};

    ret = send(tcp_client, sendbuf, strlen(sendbuf), 0);

    char recvbuf[1024] = {0};

    ret = recv(tcp_client, recvbuf, sizeof(recvbuf), 0);

    printf("recvdata:%s \r\n", recvbuf);

    close(tcp_client);

    return 0;
}